package cn.edu.seu.ssny.service.impl;

import cn.edu.seu.ssny.dao.ISelfControllerImageDao;
import cn.edu.seu.ssny.entity.Project;
import cn.edu.seu.ssny.entity.SelfControllerImage;
import cn.edu.seu.ssny.service.ISelfControllerImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class SelfControllerImageServiceImpl implements ISelfControllerImageService {

    @Autowired
    private ISelfControllerImageDao selfControllerImageDao;

    @Override
    public void save(Project project, String imagePath) {
        SelfControllerImage image = new SelfControllerImage();
        image.setProjectId(project.getId());
        image.setImagePath(imagePath);
        image.setGmtCreate(new Date());
        image.setDeleted(false);
        selfControllerImageDao.save(image);
    }

    @Override
    public void deleteByProject(Project project) {
        SelfControllerImage image = selfControllerImageDao.findByProjectId(project.getId());
        image.setGmtModified(new Date());
        image.setDeleted(true);
        selfControllerImageDao.save(image);
    }

    @Override
    public SelfControllerImage getByProject(Project project) {
        return selfControllerImageDao.findByProjectId(project.getId());
    }
}
